package com.qf.service.impl;

import com.qf.entity.Emp;
import com.qf.entity.PageInfo;
import com.qf.mapper.DeptMapper;
import com.qf.mapper.EmpMapper;
import com.qf.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

/**
 * User: key
 * ClassName:EmpServiceImpl
 * Date: 2023/5/26
 * Time: 19:38
 * description:
 */
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public List<Emp> selectAll() throws SQLException {
        return empMapper.selectAll();
    }


    @Override
    public Emp select(Emp emp) throws SQLException {
        return empMapper.select(emp);
    }

    @Override
    public Emp select(Integer eno) throws SQLException {
        return empMapper.select(eno);
    }

    @Override
    @Transactional
    public Integer insert(Emp emp) throws SQLException {
        return empMapper.insert(emp);
    }

    @Override
    @Transactional
    public Integer update(Emp emp) throws SQLException {
        return empMapper.update(emp);
    }

    @Override
    @Transactional
    public Integer delete(Integer eno) throws SQLException {
        return empMapper.delete(eno);
    }

    @Override
    @Transactional
    public Emp select(String username, String password) throws SQLException {
        return empMapper.selectBy(username,password);
    }


//    public PageInfo<Emp> findByPage(Integer currentPage) {
//        PageInfo<Emp> pageInfo = new PageInfo<>();
//        //获取每页的数据量
//        pageInfo.setSize(5);
//
//        //获取总数据量
//        int totalCount = empMapper.getTotal();//中断
//        pageInfo.setTotalCount(totalCount);
//        //获取总页数
//        int totalPage = (int)Math.ceil(totalCount/(double)pageInfo.getSize());
//        pageInfo.setTotalPage(totalPage);
//
//        //判断当前页是否合理
//        if(currentPage<1){
//            pageInfo.setCurrentPage(1);
//        }else if(currentPage>totalPage){
//            pageInfo.setCurrentPage(totalPage);
//        }else {
//            pageInfo.setCurrentPage(currentPage);
//        }
//
//        int start = (pageInfo.getCurrentPage()-1)*pageInfo.getSize();
//        //查询当前页面下所有的用户信息
//        List<Emp> list = empMapper.findByPage(start,pageInfo.getSize());
//        pageInfo.setList(list);
//        return pageInfo;
//    }
//
//    @Override
//    public PageInfo<Emp> findByPage(Integer currentPage, String username) {
//        return null;
//    }

//    @Override
//    public List<Emp> pagination(Integer start, Integer end) {
//        return empMapper.pagination(start,end);
//    }
}
